package com.wancaijinfu.widget;



import com.wancaijinfu.actitvity.R;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

public class MActionBar {
	private View layout;
	private ImageView imageView;
	private TextView titleView;
	private ImageView rightImage;
	private TextView rightTitle;
	
	private MActionBar() {
	}
	
	public static MActionBar getInstance(View view) {
		MActionBar mActionBar = new MActionBar();
		mActionBar.layout = view;
		mActionBar.imageView = (ImageView) view.findViewById(R.id.action_bar_left_image);
		mActionBar.rightImage = (ImageView) view.findViewById(R.id.action_bar_right_image);
		mActionBar.titleView = (TextView) view.findViewById(R.id.action_bar_title);
		mActionBar.rightTitle = (TextView) view.findViewById(R.id.action_bar_right_title);
		return mActionBar;
	}
	
	public void setView(View view) {
		imageView = (ImageView) view.findViewById(R.id.action_bar_left_image);
		titleView = (TextView) view.findViewById(R.id.action_bar_title);
		rightImage = (ImageView) view.findViewById(R.id.action_bar_right_image);
	}
	
	public void setActionBarRight(Drawable drawable, View.OnClickListener listener) {
		rightImage.setVisibility(View.VISIBLE);
		rightImage.setImageDrawable(drawable);
		if (listener != null)
			rightImage.setOnClickListener(listener);
	}
	
	public void setActionBarRight(int id, View.OnClickListener listener) {
		rightImage.setVisibility(View.VISIBLE);
		rightImage.setImageResource(id);
		if (listener != null)
			rightImage.setOnClickListener(listener);
	}
	
	public void setActionBarRight(String title, View.OnClickListener listener) {
		rightTitle.setVisibility(View.VISIBLE);
		rightTitle.setText(title);
		if (listener != null)
			rightTitle.setOnClickListener(listener);
	}
	
	public void setActionBarRight(View.OnClickListener listener) {
		rightImage.setVisibility(View.VISIBLE);
		rightImage.setOnClickListener(listener);
	}
	
	public void setActionBarLeft(Drawable drawable, View.OnClickListener listener) {
		imageView.setImageDrawable(drawable);
		if (listener != null)
			imageView.setOnClickListener(listener);
	}
	
	public void setActionBarLeft(int id, View.OnClickListener listener) {
		imageView.setImageResource(id);
		if (listener != null)
			imageView.setOnClickListener(listener);
	}
	
	public void setActionBarLeftDiable (){
		imageView.setVisibility(View.GONE);
	}
	
	
	
	public void setActionBarLeft(View.OnClickListener listener) {
		imageView.setOnClickListener(listener);
	}
	
	public void setActionBarTitle(int id) {
		String title = titleView.getContext().getString(id);
		titleView.setText(title);
	}
	
	public void setActionBarTitle(String title) {
		titleView.setText(title);
	}
	
	public void setDiabled() {
		layout.setVisibility(View.GONE);
	}
	
	public void setActionBarHideShadow() {
		layout.findViewById(R.id.action_bar_shadow).setVisibility(View.GONE);
	}
	
	public void startTitleAnim() {
		TranslateAnimation anim = new TranslateAnimation(
				Animation.ABSOLUTE, 300f,
				Animation.ABSOLUTE, 0f,
				Animation.RELATIVE_TO_SELF, 0f,
				Animation.RELATIVE_TO_SELF, 0f);
		anim.setDuration(1000);
		titleView.startAnimation(anim);
	}
	
	public View getRightImageView() {
		return rightImage;
	}
}
